﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;

namespace Data
{
    public abstract class DBManager
    {
        static private SqlConnection _connection;
        static public SqlConnection Connection
        {
            get { return _connection; }
            set { _connection = value; }
        }

        static private String _connStr = @"Data Source=.\SQLExpress;" +
                                  @"Initial Catalog=demoplayerdotnet;" +
                                  @"Integrated Security=True;";
        static public String ConnStr
        {
            get { return _connStr; }
            //set { _connStr = value; }
        }

        static public void Connect()
        {
            Connection = new SqlConnection(ConnStr);
            try
            {
                Connection.Open();
                //MessageBox.Show("DB Connected successfully");
            }
            catch (SqlException ex)
            {
                MessageBox.Show("DB Connection Error");
                return;
            }
        }  

        public DBManager()
        {
            if (DBManager.Connection.State == ConnectionState.Broken)
            {
                DBManager.Connection.Close();
            }
            if (DBManager.Connection.State == ConnectionState.Closed)
            {
                DBManager.Connect();
            }
        }

        private String _tableName;
        public String TableName
        {
            get { return _tableName; }
            set { _tableName = value; }
        }

        //public SqlDataReader GetRow(String[] args)
        //{
        //    SqlCommand command = Connection.CreateCommand();
        //    command.CommandText = "SELECT ";
        //    foreach(var srg in args)
        //    {
        //        command.CommandText += args + ", ";
        //    }
        //    command.CommandText += "FROM " + TableName;
        //}
    }
}
 